package model;

import helperclasses.DbUtil;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;

import javax.sql.DataSource;

import com.lowagie.text.pdf.Pfm2afm;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.JasperRunManager;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.export.JRXlsExporter;
import net.sf.jasperreports.engine.export.JRXlsExporterParameter;

import net.sf.jasperreports.swing.JRViewer;

public class HelperJasperReport {
	public HelperJasperReport() {
		// TODO Auto-generated constructor stub
	}

	public Connection getConnection() throws SQLException {
		DataSource ds = DbUtil.getInstance().getDataSource();
		Connection conn = ds.getConnection();
		return conn;
	}
	public void closeConnection() throws SQLException{
		if(getConnection() != null){
			getConnection().close();
		}
	}
	public InputStream getReportInputStream(String name){
		InputStream pdfDefinitionStream = this.getClass().getResourceAsStream("/"+ name);	
		return pdfDefinitionStream;
	}
	
	public void Zzz() throws SQLException, IOException {
		try {
			
			InputStream pdfDefinitionStream = this.getClass().getResourceAsStream("/nir_test2.jrxml");		
			JasperReport jasperReport = JasperCompileManager.compileReport(pdfDefinitionStream);
			JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, getConnection());
			//JasperExportManager.exportReportToPdfStream(jasperPrint, outputStream);
			
			
			//JasperExportManager.exportReportToPdfFile(jasperPrint, "D://sample.pdf");
			

		} catch (JRException e) {
			e.printStackTrace();
		}

	}
}
